package com.tqjc.area.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.additional.update.impl.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tqjc.area.entity.Roller;
import com.tqjc.area.entity.SteelType;
import com.tqjc.area.mapper.SteelTypeMapper;
import com.tqjc.area.service.SteelTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


@Service
public class SteelTypeServiceImpl extends ServiceImpl<SteelTypeMapper, SteelType> implements SteelTypeService {

    @Resource
    private SteelTypeMapper steelTypeMapper;

    @Override
    public SteelType queryById(Integer id) {
        return steelTypeMapper.selectById(id);
    }

    @Override
    public Page<SteelType> paginQuery(SteelType steelType, long current, long size) {
        return null;
    }

    @Override
    public SteelType insert(SteelType steelType) {
        steelTypeMapper.insert(steelType);
        return steelType;
    }

    @Override
    public SteelType update(SteelType steelType) {
        LambdaUpdateChainWrapper<SteelType> chainWrapper = new LambdaUpdateChainWrapper<SteelType>(steelTypeMapper);
        if(StrUtil.isNotBlank(steelType.getSteelType())){
            chainWrapper.eq(SteelType::getSteelType, steelType.getSteelType());
        }
        //2. 设置主键，并更新
        chainWrapper.set(SteelType::getId, steelType.getId());
        boolean ret = chainWrapper.update();
        //3. 更新成功了，查询最最对象返回
        if(ret){
            return queryById(steelType.getId());
        }else{
            return steelType;
        }
    }

    @Override
    public boolean deleteById(Integer id) {
        int total = steelTypeMapper.deleteById(id);
        return total > 0;
    }

}
